package gui.admin.mtm;

import database.TableDatabaseUsage;

import info.Ticket;

import javax.swing.table.AbstractTableModel;
import java.util.List;

public class TTM extends AbstractTableModel {

    private String[] columnNames = {"航班号","起飞时间", "机票类型", "价格","余票"};
    public List<Ticket> flightTicket = TableDatabaseUsage.getInstance().getTicketList();
    private static TTM instance = new TTM();

    public static TTM getInstance(){
        return instance;
    }
    @Override
    public int getRowCount() {
        return flightTicket.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Ticket dataInfo = flightTicket.get(rowIndex);
        if(columnIndex == 0) {
            return dataInfo.getFlight();
        } else if(columnIndex == 1) {
            return dataInfo.getFdate();
        } else if(columnIndex == 2) {
            return dataInfo.getFclass();
        } else if(columnIndex == 3) {
            return dataInfo.getPrice();
        } else if(columnIndex == 4) {
            return dataInfo.getTicket();
        }
        return null;
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];}

    public List<Ticket> getFlightTicket(){return flightTicket;}

}
